package au.csiro.nt.psdp.unit;

import junit.framework.TestCase;
import com.opensymphony.xwork2.ValidationAwareSupport;

import java.util.Collection;

/**
 *
 */
public abstract class TradelabTestCase extends TestCase
{
    protected void assertNoErrors(ValidationAwareSupport validationAware)
    {
        assertFalse(validationAware.hasErrors());
    }

    protected void assertAndClearError(String expectedError, ValidationAwareSupport validationAware)
    {
        Collection errors = validationAware.getActionErrors();
        assertEquals(1, errors.size());
        String errorMessage = (String) errors.iterator().next();
        assertEquals(expectedError, errorMessage);
        validationAware.clearErrorsAndMessages();
    }

    protected void assertAndClearMessage(String expectedMessage, ValidationAwareSupport validationAware)
    {
        Collection messages = validationAware.getActionMessages();
        assertEquals(1, messages.size());
        String actionMessage = (String) messages.iterator().next();
        assertEquals(expectedMessage, actionMessage);
        validationAware.clearErrorsAndMessages();
    }
}
